CFLAGS += -I. -fPIC
CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore)
-
LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore)
-ifeq ($(CONFIG_Linux),y)
-LIBS += -luuid
-endif
-
LIBCONFIG_URL ?= http://www.hyperrealm.com/libconfig
LIBCONFIG_SOURCE = libconfig-1.3.2
LIBCONFIG_OUTPUT = $(LIBCONFIG_SOURCE)/.libs
xs_transaction_t t;
xen_domain_handle_t handle;
- uuid_string = libxl_uuid_to_string(ctx, info->uuid);
+ uuid_string = string_of_uuid(ctx, info->uuid);
if (!uuid_string) {
- XL_LOG(ctx, XL_LOG_ERROR, "missing uuid");
+ XL_LOG(ctx, XL_LOG_ERROR, "cannot allocate uuid string");
return ERROR_FAIL;
}
flags |= info->hap ? XEN_DOMCTL_CDF_hap : 0;
*domid = 0;
- /*
- * info->uuid != xen_domain_handle_t
- * See:
- * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
- * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
- *
- * A DCE 1.1 compatible source representation of UUIDs.
- *
- * struct uuid {
- * uint32_t time_low;
- * uint16_t time_mid;
- * uint16_t time_hi_and_version;
- * uint8_t clock_seq_hi_and_reserved;
- * uint8_t clock_seq_low;
- * uint8_t node[_UUID_NODE_LEN];
- * };
- */
/* Ultimately, handle is an array of 16 uint8_t, same as uuid */
memcpy(handle, info->uuid, sizeof(xen_domain_handle_t));
int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force)
{
- char *dom_path, *uuid_str;
+ char *dom_path;
char *vm_path, *vss_path, *xapi_path;
- xen_uuid_t *uuid;
int rc, dm_present;
if (is_hvm(ctx, domid)) {
if (!dom_path)
return -1;
- if (libxl_domid_to_uuid(ctx, &uuid, domid) < 0) {
- XL_LOG(ctx, XL_LOG_ERROR, "failed ot get uuid for %d", domid);
- return -1;
- }
if (libxl_device_pci_shutdown(ctx, domid) < 0)
XL_LOG(ctx, XL_LOG_ERROR, "pci shutdown failed for domid %d", domid);
if (dm_present) {
if (!xs_rm(ctx->xsh, XBT_NULL, dom_path))
XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xs_rm failed for %s", dom_path);
- uuid_str = libxl_uuid_to_string(ctx, uuid);
-
- vm_path = libxl_sprintf(ctx, "/vm/%s", uuid_str);
+ vm_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "/local/domain/%d/vm", domid));
if (!xs_rm(ctx->xsh, XBT_NULL, vm_path))
XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xs_rm failed for %s", vm_path);
- vss_path = libxl_sprintf(ctx, "/vss/%s", uuid_str);
+ vss_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "/local/domain/%d/vss", domid));
if (!xs_rm(ctx->xsh, XBT_NULL, vss_path))
XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xs_rm failed for %s", vss_path);
libxl_domain_build_state state;
uint32_t domid;
char **args;
- xen_uuid_t uuid[16];
struct xs_permissions perm[2];
xs_transaction_t t;
libxl_device_model_starting *dm_starting = 0;
memset(&c_info, 0x00, sizeof(libxl_domain_create_info));
c_info.hvm = 0;
c_info.name = libxl_sprintf(ctx, "%s-dm", libxl_domid_to_name(ctx, info->domid));
- xen_uuid_generate(uuid);
- c_info.uuid = uuid;
+ for (i = 0; i < 16; i++)
+ c_info.uuid[i] = info->uuid[i];
memset(&b_info, 0x00, sizeof(libxl_domain_build_info));
b_info.max_vcpus = 1;
#include <xenctrl.h>
#include <xs.h>
-#include "xen_uuid.h"
-
typedef void (*libxl_log_callback)(void *userdata, int loglevel, const char *file,
int line, const char *func, char *s);
struct libxl_dominfo {
- xen_uuid_t uuid;
+ uint8_t uuid[16];
uint32_t domid;
uint8_t dying:1;
uint8_t paused:1;
bool hap;
int ssidref;
char *name;
- xen_uuid_t *uuid;
+ uint8_t uuid[16];
char **xsdata;
char **platformdata;
} libxl_domain_create_info;
typedef struct {
int domid;
+ uint8_t uuid[16]; /* this is use only with stubdom, and must be different from the domain uuid */
char *dom_name;
char *device_model;
char *saved_state;
#define PRINTF_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+#define string_of_uuid(ctx, u) \
+ libxl_sprintf(ctx, UUID_FMT, \
+ (u)[0], (u)[1], (u)[2], (u)[3], (u)[4], (u)[5], (u)[6], (u)[7], \
+ (u)[8], (u)[9], (u)[10], (u)[11], (u)[12], (u)[13], (u)[14], (u)[15])
+
/* memory allocation tracking/helpers */
int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to);
static inline int libxl_clone_context_xs(
return -1;
}
-int libxl_uuid_to_domid(struct libxl_ctx *ctx, xen_uuid_t *uuid, uint32_t *domid)
-{
- int nb_domain, i;
- struct libxl_dominfo *info = libxl_domain_list(ctx, &nb_domain);
- for (i = 0; i < nb_domain; i++) {
- if (!xen_uuid_compare(&(info[i].uuid), uuid)) {
- *domid = info[i].domid;
- free(info);
- return 0;
- }
- }
- free(info);
- return -1;
-}
-
-int libxl_domid_to_uuid(struct libxl_ctx *ctx, xen_uuid_t **uuid, uint32_t domid)
-{
- int nb_domain, i;
- struct libxl_dominfo *info = libxl_domain_list(ctx, &nb_domain);
- for (i = 0; i < nb_domain; i++) {
- if (domid == info[i].domid) {
- *uuid = libxl_zalloc(ctx, sizeof(xen_uuid_t));
- xen_uuid_copy(*uuid, &(info[i].uuid));
- free(info);
- return 0;
- }
- }
- free(info);
- return -1;
-}
-
-int libxl_is_uuid(char *s)
-{
- int i;
- if (!s || strlen(s) != UUID_LEN_STR)
- return 0;
- for (i = 0; i < UUID_LEN_STR; i++) {
- if (i == 8 || i == 13 || i == 18 || i == 23) {
- if (s[i] != '-')
- return 0;
- } else {
- if (!isxdigit((uint8_t)s[i]))
- return 0;
- }
- }
- return 1;
-}
-
-xen_uuid_t *libxl_string_to_uuid(struct libxl_ctx *ctx, char *s)
-{
- xen_uuid_t *uuid;
- if (!s || !ctx)
- return NULL;
- uuid = libxl_zalloc(ctx, sizeof(*uuid));
- xen_uuid_from_string(uuid, s);
- return uuid;
-}
-
-char *libxl_uuid_to_string(struct libxl_ctx *ctx, xen_uuid_t *uuid)
-{
- char uuid_str[UUID_LEN_STR + 3];
- if (!uuid)
- return NULL;
- xen_uuid_to_string(uuid, uuid_str, sizeof(uuid_str));
- return libxl_sprintf(ctx, "%s", uuid_str);
-}
-
-int libxl_param_to_domid(struct libxl_ctx *ctx, char *p, uint32_t *domid)
-{
- xen_uuid_t *uuid;
- uint32_t d;
-
- if (libxl_is_uuid(p)) {
- uuid = libxl_string_to_uuid(ctx, p);
- return libxl_uuid_to_domid(ctx, uuid, domid);
- }
- errno = 0;
- d = strtoul(p, (char **) NULL, 10);
- if (!errno && d != 0 && d != ULONG_MAX && d != LONG_MIN) {
- *domid = d;
- return 0;
- }
- return libxl_name_to_domid(ctx, p, domid);
-}
-
int libxl_get_stubdom_id(struct libxl_ctx *ctx, int guest_domid)
{
char * stubdom_id_s = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/image/device-model-domid", libxl_xs_get_dompath(ctx, guest_domid)));
#include "libxl.h"
-#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-
unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus);
int libxl_name_to_domid(struct libxl_ctx *ctx, char *name, uint32_t *domid);
char *libxl_domid_to_name(struct libxl_ctx *ctx, uint32_t domid);
-int libxl_uuid_to_domid(struct libxl_ctx *ctx, xen_uuid_t *uuid, uint32_t *domid);
-int libxl_domid_to_uuid(struct libxl_ctx *ctx, xen_uuid_t **uuid, uint32_t domid);
-int libxl_is_uuid(char *s);
-xen_uuid_t *libxl_string_to_uuid(struct libxl_ctx *ctx, char *s);
-char *libxl_uuid_to_string(struct libxl_ctx *ctx, xen_uuid_t *uuid);
-int libxl_param_to_domid(struct libxl_ctx *ctx, char *p, uint32_t *domid);
int libxl_get_stubdom_id(struct libxl_ctx *ctx, int guest_domid);
int libxl_is_stubdom(struct libxl_ctx *ctx, int domid);
int libxl_create_logfile(struct libxl_ctx *ctx, char *name, char **full_name);
+++ /dev/null
-/* Copyright (c) 2008, XenSource Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of XenSource Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef __XEN_UUID_H__
-#define __XEN_UUID_H__
-
-#if defined(__linux__)
-
-#include <uuid/uuid.h>
-
-typedef struct {
- uuid_t uuid;
-} xen_uuid_t;
-
-static inline int xen_uuid_is_nil(xen_uuid_t *uuid)
-{
- return uuid_is_null(uuid->uuid);
-}
-
-static inline void xen_uuid_generate(xen_uuid_t *uuid)
-{
- uuid_generate(uuid->uuid);
-}
-
-static inline void xen_uuid_to_string(xen_uuid_t *uuid, char *out, size_t size)
-{
- uuid_unparse(uuid->uuid, out);
-}
-
-static inline void xen_uuid_from_string(xen_uuid_t *uuid, const char *in)
-{
- uuid_parse(in, uuid->uuid);
-}
-
-static inline void xen_uuid_copy(xen_uuid_t *dst, xen_uuid_t *src)
-{
- uuid_copy(dst->uuid, src->uuid);
-}
-
-static inline void xen_uuid_clear(xen_uuid_t *uuid)
-{
- uuid_clear(uuid->uuid);
-}
-
-static inline int xen_uuid_compare(xen_uuid_t *uuid1, xen_uuid_t *uuid2)
-{
- return uuid_compare(uuid1->uuid, uuid2->uuid);
-}
-
-#elif defined(__NetBSD__)
-
-#include <uuid.h>
-#include <string.h>
-#include <stdlib.h>
-
-typedef uuid_t xen_uuid_t;
-
-static inline int xen_uuid_is_nil(xen_uuid_t *uuid)
-{
- uint32_t status;
- return uuid_is_nil((uuid_t *)uuid, &status);
-}
-
-static inline void xen_uuid_generate(xen_uuid_t *uuid)
-{
- uint32_t status;
- uuid_create((uuid_t *)uuid, &status);
-}
-
-static inline void xen_uuid_to_string(xen_uuid_t *uuid, char *out, size_t size)
-{
- uint32_t status;
- char *_out = NULL;
- uuid_to_string((uuid_t *)uuid, &_out, &status);
- strlcpy(out, _out, size);
- free(_out);
-}
-
-static inline void xen_uuid_from_string(xen_uuid_t *uuid, const char *in)
-{
- uint32_t status;
- uuid_from_string(in, (uuid_t *)uuid, &status);
-}
-
-static inline void xen_uuid_copy(xen_uuid_t *dst, xen_uuid_t *src)
-{
- memcpy((uuid_t *)dst, (uuid_t *)src, sizeof(uuid_t));
-}
-
-static inline void xen_uuid_clear(xen_uuid_t *uuid)
-{
- memset((uuid_t *)uuid, 0, sizeof(uuid_t));
-}
-
-static inline int xen_uuid_compare(xen_uuid_t *uuid1, xen_uuid_t *uuid2)
-{
- uint32_t status;
- return uuid_compare((uuid_t *)uuid1, (uuid_t *)uuid2, &status);
-}
-
-#else
-
-#error "Please update xen_uuid.h for your OS"
-
-#endif
-
-#ifndef UUID_LEN_STR
-#define UUID_LEN_STR (128 /*bit*/ / 4 /*nibbles*/ + 4 /*hyphens*/)
-#endif /* UUID_LEN_STR */
-
-#endif /* __XEN_UUID_H__ */
#include <stdlib.h>
#include <string.h>
#include <libconfig.h>
-#include "xen_uuid.h"
#include <unistd.h>
#include <sys/time.h> /* for time */
#include <getopt.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <xenctrl.h>
-
+#include <ctype.h>
#include "libxl.h"
#include "libxl_utils.h"
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
int logfile = 2;
void log_callback(void *userdata, int loglevel, const char *file, int line, const char *func, char *s)
write(logfile, str, strlen(str));
}
+static int domain_qualifier_to_domid(struct libxl_ctx *ctx, char *p, uint32_t *domid)
+{
+ int i, alldigit;
+
+ alldigit = 1;
+ for (i = 0; p[i]; i++) {
+ if (!isdigit(p[i])) {
+ alldigit = 0;
+ break;
+ }
+ }
+
+ if (i == 0)
+ return -1;
+ if (alldigit) {
+ *domid = strtoul(p, NULL, 10);
+ return 0;
+ } else {
+ /* check here if it's a uuid and do proper conversion */
+ }
+ return libxl_name_to_domid(ctx, p, domid);
+}
+
#define LOG(_f, _a...) dolog(__FILE__, __LINE__, __func__, _f, ##_a)
void dolog(const char *file, int line, const char *func, char *fmt, ...)
static void init_dm_info(libxl_device_model_info *dm_info,
libxl_domain_create_info *c_info, libxl_domain_build_info *b_info)
{
+ int i;
memset(dm_info, '\0', sizeof(*dm_info));
+ for (i = 0; i < 16; i++) {
+ dm_info->uuid[i] = rand();
+ }
+
dm_info->dom_name = c_info->name;
dm_info->device_model = "/usr/lib/xen/bin/qemu-dm";
dm_info->videoram = b_info->video_memkb / 1024;
libxl_device_model_info *dm_info)
{
int i;
- char uuid_str[37];
printf("*** domain_create_info ***\n");
printf("hvm: %d\n", c_info->hvm);
printf("hap: %d\n", c_info->hap);
printf("ssidref: %d\n", c_info->ssidref);
printf("name: %s\n", c_info->name);
- xen_uuid_to_string(c_info->uuid, uuid_str, sizeof(uuid_str));
- printf("uuid: %s\n", uuid_str);
+ printf("uuid: " UUID_FMT "\n",
+ (c_info->uuid)[0], (c_info->uuid)[1], (c_info->uuid)[2], (c_info->uuid)[3],
+ (c_info->uuid)[4], (c_info->uuid)[5], (c_info->uuid)[6], (c_info->uuid)[7],
+ (c_info->uuid)[8], (c_info->uuid)[9], (c_info->uuid)[10], (c_info->uuid)[11],
+ (c_info->uuid)[12], (c_info->uuid)[13], (c_info->uuid)[14], (c_info->uuid)[15]);
if (c_info->xsdata)
printf("xsdata: contains data\n");
else
libxl_device_model_info *dm_info)
{
const char *buf;
- xen_uuid_t uuid[16];
long l;
struct config_t config;
struct config_setting_t *vbds, *nics, *pcis, *cvfbs;
int pci_power_mgmt = 0;
int pci_msitranslate = 1;
+ int i;
config_init (&config);
c_info->name = strdup(buf);
else
c_info->name = "test";
- xen_uuid_generate(uuid);
- c_info->uuid = uuid;
+ for (i = 0; i < 16; i++) {
+ c_info->uuid[i] = rand();
+ }
init_build_info(b_info, c_info);
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, p, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", p);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, p, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", p);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, dom, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", dom);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, dom, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", dom);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, dom, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", dom);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, dom, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", dom);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, p, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", p);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, p, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", p);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, p, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", p);
exit(2);
}
libxl_ctx_init(&ctx, LIBXL_VERSION);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- if (libxl_param_to_domid(&ctx, p, &domid) < 0) {
+ if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", p);
exit(2);
}